package scalab.utils

import java.text.DateFormat
import java.util.Date
/*
sealed trait Stopwatch{

	import java.sql.Time

	val formater: DateFormat

	var startDate: Date = _
	var stopDate: Date = _

	def start = {
		startDate = new Date
	}

	def stop = {
		stopDate = new Date
	}

	def elapsed: long = stopDate.getTime - startDate.getTime

	lazy val elapsedTime = new Time(elapsed)

	override def toString: String = elapsedTime.toString
}

object Stopwatch{
	import scalab.core.component.ExecutableComponent
	
	def apply(dateFormater: DateFormat, component: ExecutableComponent): Stopwatch = {
		import scalab.core.event.{Event, ExecutionStarted, ExecutionFinished, Listener}
		val watch = new Stopwatch{
			override val formater: DateFormat = dateFormater
		}
		
		val l1: Listener[ExecutionStarted] = new Listener[ExecutionStarted]{
			def react[ExecutionStarted](event: ExecutionStarted) = {
				watch.start
				component.info("Started at: " + watch.formater.format(watch.startDate))
			}
		}
		val l2: Listener[ExecutionFinished] = new Listener[ExecutionFinished]{
			def react[ExecutionFinished](event: ExecutionFinished) = {
				watch.stop
				component.info("Ended at: " + watch.formater.format(watch.stopDate))
				component.info("Time elapsed: " + watch.toString)
			}
		}
		
		component.listenEndExecution(l2.asInstanceOf[Listener[Event]])
		component.listenStartExecution(l1.asInstanceOf[Listener[Event]])
		watch
	}

	def apply(component: ExecutableComponent): Stopwatch = {
		import java.text.SimpleDateFormat
		apply(new SimpleDateFormat, component)
	}

	def apply(components: Iterable[ExecutableComponent]): Iterable[Stopwatch] = {
		import java.text.SimpleDateFormat
		apply(new SimpleDateFormat, components)
	}

	def apply(components: ExecutableComponent*): Iterable[Stopwatch] = apply(components)

	def apply(dateFormater: DateFormat, components: Iterable[ExecutableComponent]): Iterable[Stopwatch] = 
		components map {c => apply(dateFormater, c)}

	def apply(dateFormater: DateFormat, components: ExecutableComponent*): Iterable[Stopwatch] = 
		apply(dateFormater, components)

}*/
